<template>
	<view class="center">
		<uni-easyinput class="uni-mt-5" suffixIcon="search" v-model="info.keyword" placeholder="搜索内容" @iconClick="iconClick">
		</uni-easyinput>
		<uni-list :border="false">
			<xbd-new-card v-for="(item,index) in showList" :key="index" :msgInfo='item' @click="click"></xbd-new-card>
			<xbd-null-list v-if="!showList.length"></xbd-null-list>
			<xbd-loading-more v-if="showList.length" :status-num="statusNum" :is-load-more="isLoadMore">
			</xbd-loading-more>
		</uni-list>

	</view>
</template>

<script>
	import Index from '@/api/item/index.js';
	export default {
		data() {
			return {
				statusNum: 0,
				isLoadMore: false,
				value: '',
				showList: [],
				info: {
					page: 1,
					perpage: 10,
					module: this.tab1val,
					keyword:''
				}
			};
		},
		methods: {
			// 搜索
			iconClick() {
				this.info.page = 1
				this.showList = []
				console.log('就是玩')
				this.init()
			},
				
			click(id){
				console.log(id)
				uni.navigateTo({
					url: `/pages/index/news/news?id=${id}`,
				});
			},
			async init() {
				const res = await Index.getHome(this.info)
				console.log(res,'res')
				if (res.data.list.length === this.info.perpage) {
					this.isLoadMore = true;
					this.statusNum = 2;
				}
				this.showList = res.data.list
			},
			// 加载更多
			loadmore() {
				this.info.page++;
				this.statusNum = 1;
				this.isLoadMore = true;
				this.loadmoreList();
			},
			async loadmoreList() {
				try {
					const res = await Index.getHome(this.info);
					if (res.data.list.length) {
						this.showList = this.showList.concat(res.data.list);
						if (res.data.list.length === this.info.perpage) {
							this.statusNum = 2;
						} else {
							this.statusNum = 0;
						}
						// this.isLoadMore = false;
					} else {
						this.info.page--;
						this.statusNum = 0;
					}
				} catch (e) {
					uni.hideLoading();
					this.info.page--;
				}
			},
		},
		async onLoad(res) {
			uni.setNavigationBarTitle({
				title: res.msg
			});
			if (res.type == 1) {
				this.info = {
					page: 1,
					perpage: 10,
					module: res.msg,
					keyword:''
				}
			} else {
				this.info = {
					page: 1,
					perpage: 10,
					module: '廉政文化',
					culture: res.msg,
					keyword:''
				}
			}
			await this.init()

		},
		// 触底触发
		onReachBottom() {
			// 当下拉组件显示状态 并且显示不是没有数据了 时才进行下拉加载
			console.log('触底操作')
			if (this.isLoadMore && this.statusNum !== 0) {
				this.loadmore();
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-icons {
		margin-right: 20rpx;
	}
	
	::v-deep .uni-easyinput__content-input {
		font-size: 30rpx;
	}
	::v-deep .uni-list {
		background-color: #FFFFFF;
		border-radius: 16rpx;
		// &:nth-child(n){
		// 	margin-bottom: 40rpx;
		// }
	}

	.center {
		padding: 32rpx;

		// background-color: #fff;
		.search {
			// padding:32rpx;
			// background-color: #FFFFFF;
			margin-bottom: 20rpx;
		}

		.uni-mt-5 {
			margin-bottom: 20rpx;
		}
	}
</style>
